package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.vendorMapper;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.vendor;
import com.itheima.pojo.vendorQueryParam;
import com.itheima.service.vendorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class vendorServiceImpl implements vendorService {
    @Autowired
    private vendorMapper vendormapper;


    @Override
    public PageBean getpageInfo(vendorQueryParam vendorQueryParam) {
        //设置分页参数
        PageHelper.startPage(vendorQueryParam.getPage(), vendorQueryParam.getPageSize());
        List<vendor> vendorList = vendormapper.getPageInfo(vendorQueryParam);
        Page<vendor> page = (Page<vendor>) vendorList;
        return new PageBean(page.getTotal(), page.getResult());
    }

    @Override
    public void addVendor(vendor vendor) {
        vendormapper.addVebdor(vendor);
    }

    @Override
    public void deletevendor(List<Integer> ids) {
        vendormapper.deletevendor(ids);
    }

    @Override
    public List<vendor> findAll() {
        return  vendormapper.getPageInfo(null);
    }

    @Override
    public vendor findByidVendor(Integer id) {
        return vendormapper.findVendor(id);
    }

    @Override
    public void updateVendor(vendor vendor) {
        vendormapper.updateVendor(vendor);
    }
}
